package com.demo7;

import com.alibaba.fastjson.JSONObject;
import org.json.JSONException;

import java.util.Collection;
import java.util.Hashtable;
import java.util.Map;

public class CollectorError {
    private static Map errorMap = new Hashtable();

    public enum TYPE {
        ERROR_INIT(qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("cntp", "BKYBTTYN", "t-WwLJmG")),
        ERROR_JNI(qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("an91", "XODUI!LU", "ayIAADuJ")),
        ERROR_PROFILE_DELAY(qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("HVJi", "-cP+#HEI", "SeOJCwrN"));

        private String code;

        TYPE(String str) {
            this.code = str;
        }

        public String code() {
            return this.code;
        }
    }

    static {
        addError(TYPE.ERROR_INIT, qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("HScdeCE6O3owIA83JDBvMzcnDQ==", "YNyXOUOZ", "ojevneqc"));
    }

    public static void addError(TYPE type, String str) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("CCYVIg4e", "zCtQapcs", "+lnn-Lxo"), str);
        } catch (JSONException e9) {
            qgqqqgqg99gq.qqggqqqgqgqqgqqg9qgg(e9.toString());
        }
        addError(type, jSONObject);
        qgqqqgqg99gq.q99qqgggqqgg9qg99g99g(qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("PCcILDlaNQk9dRslPx8mVw==", "YUzCKzTm", "E!BlS!Nm") + errorMap.toString());
    }

    public static void addError(TYPE type, JSONObject jSONObject) {
        String str;
        if (errorMap == null) {
            errorMap = new Hashtable();
        }
        if (errorMap.containsKey(type.code())) {
            if (jSONObject != null) {
                str = jSONObject.toString();
                if (str == null) {
                    str = qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("", "kWQQD#K+", "f*VKb#K$");
                }
                String str2 = (String) errorMap.get(type.code);
                qgqqqgqg99gq.q99qqgggqqgg9qg99g99g(qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("I1MXJhkbL1E1Gw==", "F!eIkvN!", "dwVysXtv") + str2);
                if (str2 != null) {
                    if (!str2.contains(str)) {
                        str = str2 + qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("Rwo=", "k*shCbkY", "!fnB$$TF") + str;
                    } else {
                        return;
                    }
                }
            } else {
                return;
            }
        } else if (jSONObject != null) {
            str = jSONObject.toString();
            if (str == null) {
                str = qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("", "BxuDQUaT", "t#TPrz!$");
            }
        } else {
            errorMap.put(type.code(), qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("Vj4=", "-CWGUr&n", "NCpL*dpw"));
            return;
        }
        errorMap.put(type.code(), str);
    }


    public static JSONObject catchErr(Throwable th) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put(qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("FSgwMjgm", "gMQAWHQk", "M-fcvct$"), th.getLocalizedMessage());
            jSONObject.put(qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("NjwCMQ==", "BErTBwy+", "I!OyNWwS"), th.getClass().getName());
            StackTraceElement[] stackTrace = th.getStackTrace();
            int i9 = 0;
            while (true) {
                if (i9 >= stackTrace.length) {
                    break;
                } else if (stackTrace[i9].getClassName().contains(qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("EQd3VS8kLDQHB3dALi45PxsN", "riY!@JKP", "T-#pOFci"))) {
                    break;
                } else {
                    i9++;
                }
            }
            return jSONObject;
        } catch (Throwable unused) {
            return new JSONObject();
        }
    }


    public static String getErrorCode() {
        Map map = errorMap;
        return map != null ? map.keySet().toString() : qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg("", "iVqPpos+", "GHI+ReMA");
    }

    public static String getErrorMsg() {
        String str;
        String str2;
        String str3;
        Map map = errorMap;
        if (map == null) {
            str = "fR8=";
            str2 = "&Bkcm$pc";
            str3 = "$#!hlK#M";
        } else if (map.size() <= 0) {
            str = "HBI=";
            str2 = "GOnM$gl&";
            str3 = "nWmRwonN";
        } else {
            Collection values = errorMap.values();
            if (values.size() > 0) {
                return values.toString();
            }
            str = "cHs=";
            str2 = "+&pRvfLU";
            str3 = "xInSRbkv";
        }
        return qqg9q9qq99999g9qggq9.qqggqqqgqgqqgqqg9qgg(str, str2, str3);
    }

    public static void remove(TYPE type) {
        Map map = errorMap;
        if (map != null && map.containsKey(type.code)) {
            errorMap.remove(type.code());
        }
    }
}
